import Vue from 'vue'
import VueRouter, { RouteConfig } from 'vue-router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({ showSpinner: false })

import NotFound from '@/views/NotFound.vue'

Vue.use(VueRouter)

const routes: Array<RouteConfig> = [
    {
        path: '/',
        redirect: { name: 'home' },
    },
    {
        path: '/home',
        name: 'home',
        component: () => import(/* webpackChunkName: "home" */ '../views/HomeView.vue'),
    },
    {
        path: '/about',
        name: 'about',
        meta: { title: '关于我们' },
        component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue'),
        redirect: { name: 'aboutus' },
        children: [
            {
                path: '/about/team',
                name: 'team',
                meta: { title: '技术团队' },
                component: () => import(/* webpackChunkName: "about" */ '../views/about/AboutTeam.vue'),
            },
            {
                path: '/about/aboutus',
                name: 'aboutus',
                meta: { title: '公司简介' },
                component: () => import(/* webpackChunkName: "about" */ '../views/about/AboutUs.vue'),
            },
            {
                path: '/about/achievement',
                name: 'achievement',
                meta: { title: '研发成果' },
                component: () => import(/* webpackChunkName: "about" */ '../views/about/AboutAchieve.vue'),
            },
        ],
    },
    {
        path: '/synthesis',
        name: 'synthesis',
        meta: { title: '定制合成' },
        component: () => import(/* webpackChunkName: "synthesis" */ '../views/SynthesisView.vue'),
        redirect: { name: 'process' },
        children: [
            {
                path: '/synthesis/process',
                name: 'process',
                meta: { title: '定制流程' },
                component: () => import(/* webpackChunkName: "synthesis" */ '../views/synthesis/SynthesisProcess.vue'),
            },
            {
                path: '/synthesis/variety',
                name: 'variety',
                meta: { title: '优势品种' },
                component: () => import(/* webpackChunkName: "synthesis" */ '../views/synthesis/SynthesisVariety.vue'),
            },
        ],
    },
    {
        path: '/product',
        name: 'product',
        component: () => import(/* webpackChunkName: "products" */ '../views/product/ProductIndex.vue'),
    },
    {
        path: '/search',
        name: 'search',
        component: () => import(/* webpackChunkName: "products" */ '../views/product/ProductSearch.vue'),
    },
    {
        path: '/productlist',
        name: 'productlist',
        component: () => import(/* webpackChunkName: "products" */ '../views/product/ProductList.vue'),
    },
    {
        path: '/product-detail',
        name: 'product-detail',
        component: () => import(/* webpackChunkName: "products" */ '../views/product/ProductDetail.vue'),
    },
    {
        path: '/products',
        name: 'products',
        component: () => import(/* webpackChunkName: "products" */ '../views/ProductView.vue'),
        children: [
            {
                path: '/products/impurity',
                name: 'impurity',
                meta: { title: '杂质对照品' },
                component: () => import(/* webpackChunkName: "products" */ '../views/product/ProductCenter.vue'),
            },
            {
                path: '/products/isotope',
                name: 'isotope',
                meta: { title: '稳定同位元素' },
                component: () => import(/* webpackChunkName: "products" */ '../views/product/ProductCenter.vue'),
            },
            {
                path: '/products/api',
                name: 'api',
                meta: { title: 'API' },
                component: () => import(/* webpackChunkName: "products" */ '../views/product/ProductCenter.vue'),
            },
        ],
    },
    {
        path: '/information',
        name: 'information',
        meta: { title: '资讯中心' },
        component: () => import(/* webpackChunkName: "information" */ '../views/NewsView.vue'),
        redirect: { name: 'news' },
        children: [
            {
                path: '/information/news',
                name: 'news',
                meta: { title: '新闻中心' },
                component: () => import(/* webpackChunkName: "information" */ '../views/news/InfoList.vue'),
            },
            {
                path: '/information/activity',
                name: 'activity',
                meta: { title: '活动中心' },
                component: () => import(/* webpackChunkName: "information" */ '../views/news/InfoList.vue'),
            },
        ],
    },
    {
        path: '/news-detail',
        name: 'news-detail',
        component: () => import(/* webpackChunkName: "news" */ '../views/news/NewsDetail.vue'),
    },
    {
        path: '/contact',
        name: 'contact',
        component: () => import(/* webpackChunkName: "contact" */ '../views/ContactView.vue'),
    },
    {
        path: '*',
        component: NotFound,
    },
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes,
})

router.beforeEach((to, from, next) => {
    NProgress.start()
    next()
})
router.afterEach(() => {
    NProgress.done()
})

export default router
